define([
	'models/tweet'
], function(Tweet){
	var getTweetPublicProvider = function (username){
		$.ajax({
			type:'GET',
			dataType:'jsonp',
			data:{screen_name:username, include_rts:1},
			url:'http://api.twitter.com/1/statuses/user_timeline.json',
			success:function(data, textStatus, XMLHttpRequest) {
				for(i in data) {
					var tweetmodel = new Tweet();
					if(data[i].retweeted_status != null) {
						tweetmodel.set({
							id: data[i].retweeted_status.id_str,
							name: data[i].retweeted_status.user.name,
							screenname: data[i].retweeted_status.screen_name,
							datecreate: data[i].retweeted_status.created_at,
							text: data[i].retweeted_status.text,
							retweets: data[i].retweeted_status.retweet_count,
							favorites: data[i].retweeted_status.favourites_count,
							isretweet: data[i].retweeted_status.retweeted,
							isfavorite: data[i].retweeted_status.favorited,
							url: data[i].retweeted_status.user.profile_image_url
						});
						if(data[i].retweeted_status.favorited) {
							tweetmodel.set({isfavorite: true});
						}
					} else {
						tweetmodel.set({
							id: data[i].id_str,
							name: data[i].user.name,
							screenname: data[i].screen_name,
							datecreate: data[i].created_at,
							text: data[i].text,
							retweets: data[i].retweet_count,
							favorites: data[i].favourites_count,
							isretweet: data[i].retweeted,
							isfavorite: data[i].favorited,
							url: data[i].user.profile_image_url
						});
						if(data[i].favorited) {
							tweetmodel.set({isfavorite: true});
						}
					}
					tweets.add(tweetmodel);
				}
			},
			error: function(req, status, error){
				alert('error: '+status);
			}
		});
	}
	return{
		getTweetPublicProvider: getTweetPublicProvider
	}
});